home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / answers / news / macintosh / programmer-faq / part2 < prev    next >
Internet Message Format  |  1993-08-30  |  27KB

  1. Path: senator-bedfellow.mit.edu!bloom-beacon.mit.edu!pad-thai.aktis.com!pad-thai.aktis.com!not-for-mail
  2. From: Daryl_Spitzer@mindlink.bc.ca (Daryl Spitzer)
  3. Newsgroups: comp.sys.mac.programmer,news.answers
  4. Subject: Comp.Sys.Mac.Programmer FAQ Part 2/2 (1/12/93)
  5. Supersedes: <macintosh/programmer-faq/part2_746164809@GZA.COM>
  6. Followup-To: poster
  7. Date: 31 Aug 1993 00:00:16 -0400
  8. Organization: none
  9. Lines: 743
  10. Sender: faqserv@GZA.COM
  11. Approved: news-answers-request@MIT.Edu
  12. Distribution: world
  13. Expires: 21 Sep 1993 04:00:09 GMT
  14. Message-ID: <macintosh/programmer-faq/part2_746769609@GZA.COM>
  15. References: <macintosh/programmer-faq/part1_746769609@GZA.COM>
  16. Reply-To: Daryl_Spitzer@mindlink.bc.ca
  17. NNTP-Posting-Host: pad-thai.aktis.com
  18. Summary: Frequently Asked Questions list for comp.sys.mac.programmer
  19. Keywords: frequently asked questions faq
  20. X-Last-Updated: 1993/01/20
  21. Xref: senator-bedfellow.mit.edu comp.sys.mac.programmer:68127 news.answers:11922
  22.  
  23. Archive-name: macintosh/programmer-faq/part2
  24. Last-modified: 1993/01/12
  25.  
  26.  
  27.                      +---------------------------------+
  28.                      | Frequently Asked Questions List |
  29.                      |   for Comp.Sys.Mac.Programmer   |
  30.                      |         January 12, 1993        |
  31.                      |            PART  TWO            |
  32.                      +---------------------------------+
  33.  
  34.  
  35. This FAQ list is automatically posted once a week to comp.sys.mac.programmer.
  36. It is also available via anonymous ftp from ftp.cs.uoregon.edu [128.223.8.8]
  37. (user name 'anonymous', your internet address as password) in the files
  38. /pub/mac/csmp-faq-1 and /pub/mac/csmp-faq-2.
  39.  
  40. This FAQ list is maintained by Daryl Spitzer.  He can be reached at the
  41. following addresses:
  42.  
  43.    Internet:  Daryl_Spitzer@mindlink.bc.ca
  44.    SnailMail: 203 - 1385 West 12th Avenue
  45.               Vancouver, BC  (Canada)
  46.               V6H 1M2
  47.  
  48. The purpose of the FAQ list is to answer some of the most common questions
  49. asked on this group, and to refer people left with unanswered questions to
  50. available sources of additional help.  You should read the FAQ list before
  51. posting to comp.sys.mac.programmer.
  52.  
  53. Submissions, comments, etcetera, should be sent to Daryl Spitzer, as above.
  54. All such material sent will be considered to have entered the public domain
  55. (and will be subject to editing) unless specific text to the contrary
  56. accompanies the message (which may render the submission unusable).
  57.  
  58.  
  59.  
  60.                          Changes since August 3, 1992
  61.                          ----------------------------
  62.  
  63.  - the keeper of the FAQ is now Daryl Spitzer (Daryl_Spitzer@mindlink.bc.ca)
  64.  
  65.  - 1.2  Debuggers:
  66.     added Fritz Anderson's description of SourceBug
  67.  
  68.  - 2.1  The Associates and Partners Programs:
  69.     new description, DEVHOTLINE is no longer a valid AppleLink address
  70.  
  71.  - 2.3  APDA
  72.     new address and telephone numbers
  73.  
  74.  - 3.1.1  Technical Books
  75.     new Inside Macintosh volumes
  76.  
  77.  - 3.1.3  Periodicals:
  78.     MacTutor is now MacTech
  79.  
  80.  
  81.  
  82.  
  83.                               Table of Contents
  84.                               -----------------
  85.  
  86. Part One  (separate file)
  87. ---------------------
  88.  
  89.   I.    Development Software
  90.           1. Compilers
  91.           2. Debuggers
  92.           3. Other Tools
  93.  
  94.   II.   Apple Developer Programs
  95.           1. The Associates and Partners Programs
  96.           2. Apple Developer University
  97.           3. APDA
  98.           4. Developer CDs
  99.  
  100.   III.  Sources of Information
  101.           1. Books and Periodicals
  102.                1. Technical Books
  103.                2. Teaching Books
  104.                3. Periodicals
  105.           2. Mailing Lists
  106.                1. Comp.Sys.Mac.Programmer Digest
  107.                2. Think Class Library Discussion
  108.                3. MacPsych
  109.           3. Miscellaneous
  110.                1. Usenet Mac Programmer's Guide (UMPG)
  111.                2. Kent Sandvik's Frequently Asked MPW C++ and MacApp
  112. Questions
  113.                3. Comp.Sys.Mac.FAQ
  114.  
  115.   IV.   Archive Sites
  116.           1. ftp.apple.com [130.43.2.3]
  117.           2. sumex-aim.stanford.edu [36.44.0.6]
  118.           3. rascal.ics.utexas.edu [128.83.138.20]
  119.           4. mac.archive.umich.edu [141.211.164.153]
  120.           5. ftp.cs.uoregon.edu [128.223.8.8]
  121.           6. ics.uci.edu [128.195.1.1]
  122.           7. ftp.brown.edu [128.148.176.55]
  123.           8. comp.binaries.mac [newsgroup]
  124.  
  125.   V.    One-liners
  126.           1. The Main Loop and Events
  127.           2. Menus
  128.           3. Resources
  129.           4. Windows, Alerts, and Dialogs
  130.           5. Drawing
  131.           6. Files
  132.           7. Interrupts and VBL Tasks
  133.           8. Handles and Pointers
  134.           9. General
  135.  
  136.  
  137. Part Two  (this file)
  138. -------------------------
  139.  
  140.   VI.   Specific Questions Answered
  141.           1. The Main Loop and Events
  142.                1. How do you tell if a specific key is being pressed?
  143.                2. How can I get millisecond timing from the keyboard
  144.                   (or mouse)?
  145.           2. Menus
  146.                1. When do you put an ellipsis on the end of a menu item?
  147.                2. How do I get the menubar to disappear and re-appear?
  148.                3. What's the difference between the resource ID of a 'MENU'
  149.                   resource and the menuID field of that resource?
  150.           3. Windows, Alerts, and Dialogs
  151.                1. How do you put a border around the default button in a
  152.                   dialog?
  153.           4. Drawing
  154.                1. What is the fastest way to paint one pixel on the screen?
  155.                2. How do you draw directly into a pixmap without using
  156.                   QuickDraw?
  157.                3. How do you draw directly onto the screen without using
  158.                   QuickDraw?
  159.                4. What RGB value does the system use for dimmed buttons,
  160.                   menus and window titles?
  161.           5. Files
  162.                1. Why is the File Manager so hard to use?
  163.                2. How do you get a full pathname?
  164.                3. How do you set the SFGet/PutFile directory?
  165.                4. How do you access the application's data fork?
  166.           6. Handles and Pointers
  167.                1. When should I call MoveHHi?
  168.                2. Why does malloc/calloc keep crashing or returning NULL in
  169.                   Think C?
  170.           7. Standalone Code
  171.                1. How do I write an INIT?
  172.           8. General
  173.                1. How do I register signatures and file types with Apple?
  174.                2. How do I go about writing serial port communications?
  175.  
  176.  
  177.   VII.  Eternal Debates:
  178.           1. Why doesn't the Mac do preemptive multitasking?
  179.  
  180.  
  181.  
  182. =============================================================================
  183.  
  184.  
  185.                  ===========================================
  186.                    Section VI: Specific Questions Answered
  187.                  ===========================================
  188.  
  189.  
  190.  
  191. 6.1  The Main Loop and Events
  192. -----------------------------
  193.  
  194.  
  195. ----------------------------------------------------------
  196. 6.1.1  How do you tell if a specific key is being pressed?
  197. ----------------------------------------------------------
  198.  
  199. Use GetKeys.  GetKeys fills a 16-byte KeyMap structure with the state of
  200. every key.  Each bit represents a single key on the keyboard; 1 means the
  201. key is down, 0 means it is up.  Note that there can be a maximum of seven
  202. keys being pressed at a time - any of the modifier keys plus at most two
  203. other keys.
  204.  
  205. Here's an example in C:
  206.  
  207. Boolean IsKeyDown(
  208.     unsigned short theKey )  // a keyboard-specific scan code for a key
  209. {
  210.  
  211.     unsigned char  keyMap[16];
  212.  
  213.     GetKeys( (void *) keyMap );
  214.     return ((keyMap[theKey>>3] >> (theKey & 7)) & 1);
  215.  
  216. }
  217.  
  218.  
  219.  
  220. -----------------------------------------------------------------------------
  221. 6.1.2  I'm writing a psychology experiment.  How can I get millisecond timing
  222.        from the keyboard (or mouse)?
  223. -----------------------------------------------------------------------------
  224.  
  225. The simple answer is that you can't.  Although the new time manager can call
  226. routines every couple of microseconds, input goes through the event manager,
  227. which only posts events about every 16 milliseconds.  Thus, even if you poll
  228. the keyboard every 30 microseconds, you will not get better than 16 ms.
  229. resolution.  If you really need millisecond accuracy, you need to use
  230. external hardware.
  231.  
  232. The good news is that you probably don't need better than 16 ms. resolution
  233. anyway.  Measuring with 16 ms. accuracy only increases the standard deviation
  234. of your RT means by about 4.8 msec.  Read: Ulrich, R. and Giray, M. (1989).
  235. Time resolution of clocks: Effects on reaction time measurement -- Good news
  236. for bad clocks.  British Journal of Mathematical and Statistical Psychology,
  237. 42, 1-12.
  238.  
  239. By the way, there is a mailing list dedicated to running psychology
  240. experiments on the Mac.  It frequently gets tied up in arguments about
  241. millisecond timing.  The address to write to is macpsych-request@stolaf.edu.
  242.  
  243.  
  244.  
  245.  
  246. 6.2  Menus
  247. ----------
  248.  
  249.  
  250. -------------------------------------------------------------
  251. 6.2.1  When do you put an ellipsis on the end of a menu item?
  252. -------------------------------------------------------------
  253.  
  254. Put an ellipsis (...) at the end of any menu item which requires more
  255. information in order to complete or simply displays information.  Usually
  256. this involves a dialog of some kind, be it modal or non modal.
  257.  
  258.  
  259.  
  260. -----------------------------------------------------------
  261. 6.2.2  How do I get the menubar to disappear and re-appear?
  262. -----------------------------------------------------------
  263.  
  264. A set of routines to do this in Pascal can be found in the Usenet
  265. Macintosh Programmer's Guide.  You can also ftp some sample code in C
  266. from skinner.cs.uoregon.edu in /pub/mac/menu-bar.c.
  267.  
  268.  
  269.  
  270. -----------------------------------------------------------------------------
  271. 6.2.3  What's the difference between the resource ID of a 'MENU' resource and
  272.        the menuID field of that resource?
  273. -----------------------------------------------------------------------------
  274.  
  275. The resource ID of a 'MENU' resource is just the resource ID - it has no
  276. hidden meaning.  What is normally expected by beginning programmers is that
  277. the number that MenuSelect and MenuKey return is the resource ID of the menu.
  278. In fact, the number returned is the value of the menuID field of the menu,
  279. and has no relation to the resource ID of the menu.  You can set the menuID
  280. to any number you want, but by convention it is expected to be the same as
  281. the resource ID of the menu.  (You can change this value in ResEdit by
  282. opening the menu you wish to change, and selecting 'Edit Menu & MDEF ID...'
  283. from the MENU menu.)
  284.  
  285.  
  286.  
  287.  
  288. 6.3  Windows, Alerts, and Dialogs
  289. ---------------------------------
  290.  
  291.  
  292. ---------------------------------------------------------------------
  293. 6.3.1  How do you put a border around the default button in a dialog?
  294. ---------------------------------------------------------------------
  295.  
  296. The most common way to do this is to create a dummy user item in the dialog,
  297. and use SetDItem to install a procedure that outlines the default button.
  298. The dialog's "Initially visible" bit should be false and you should call
  299. ShowWindow before calling ModalDialog; otherwise, if the button is very tall,
  300. part of the outline won't be drawn.  Here is an example in C:
  301.  
  302.  
  303. /* This function draws a border around dialog item #1 */
  304.  
  305. pascal void OutlineDefault(
  306.     DialogPtr theDialog,
  307.     short     theItem )
  308. {
  309.  
  310.     Rect     itemRect;
  311.     Handle   itemHandle;
  312.     short    itemType;
  313.     short    diameter;
  314.  
  315.     GetDItem( theDialog, 1, &itemType, &itemHandle, &itemRect );
  316.     diameter = (itemRect.bottom - itemRect.top) / 2 + 6;
  317.     if ( diameter < 16 )
  318.         diameter = 16;
  319.     PenSize( 3, 3 );
  320.     InsetRect( &itemRect, -4, -4 );
  321.     FrameRoundRect( &itemRect, diameter, diameter );
  322.  
  323. }
  324.  
  325.  
  326.  
  327. /* Assume myDialog has been initialized, and item #4 is the dummy
  328.    user item for outlining the default button.  The following lines
  329.    install the outlining procedure OutlineDefault into the user
  330.    item, so that OutlineDefault will be called by the Dialog Manager
  331.    each time the dialog needs to be redrawn.  Depending on your
  332.    compiler, you may have to cast OutlineDefault to a Handle. */
  333.  
  334. GetDItem( myDialog, 4, &itemType, &itemHandle, &itemRect );
  335. SetDItem( myDialog, 4, itemType, OutlineDefault, &itemRect );
  336.  
  337.  
  338.  
  339.  
  340. 6.4  Drawing
  341. ------------
  342.  
  343.  
  344. ----------------------------------------------------------------
  345. 6.4.1  What is the fastest way to paint one pixel on the screen?
  346. ----------------------------------------------------------------
  347.  
  348. Using QuickDraw, the fastest way to draw one pixel is
  349.    MoveTo( x, y );
  350.    Line( 0, 0 );
  351. making sure that the pen size is 1 by 1.  This is about twice as fast as
  352. setting the pen size to 0 by 1 or 1 by 0 and calling Line( 1, 0 ) or
  353. Line( 0, 1 ), respectively.  I'm not sure why....
  354.  
  355. See below for how to draw a pixel without using QuickDraw.
  356.  
  357.  
  358.  
  359. ----------------------------------------------------------------------
  360. 6.4.2  How do you draw directly into a pixmap without using QuickDraw?
  361. ----------------------------------------------------------------------
  362.  
  363. As an example, here is a routine that paints a single pixel in a pixmap.
  364. To use this procedure, you just have to know what 'value' to pass in.  This
  365. depends on the current bit-depth of 'thePixMap.'  The rightmost n bits of
  366. 'value' are used for the pixel value for depth = n.  For depths of eight or
  367. less, the value of each pixel is an index into a color table.  For depth =
  368. 16,
  369. each 16-bit pixel is interpreted as an RGB value, as follows:
  370.  
  371.          Bit: 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
  372.        Value:  R  R  R  R  R  G  G  G  G  G  B  B  B  B  B  U
  373.  
  374. where R = Red, G = Green, B = Blue, and U = Unused.  For depth = 32, each
  375. 32-bit pixel is interpreted as an RGB value as follows:
  376.  
  377.          Bit: 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
  378.        Value:  A  A  A  A  A  A  A  A  R  R  R  R  R  R  R  R
  379.  
  380.          Bit: 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
  381.        Value:  G  G  G  G  G  G  G  G  B  B  B  B  B  B  B  B
  382.  
  383. where R = Red, G = Green, B = Blue, and A = Alpha.
  384.  
  385.  
  386.  
  387. void SetPixel(
  388.     short           x,
  389.     short           y,
  390.     long            value,
  391.     PixMapHandle    thePixMap )
  392. {
  393.  
  394.     unsigned long   rowBytes;
  395.     unsigned char   mask;
  396.     unsigned char   shiftBits;
  397.     unsigned char   *thePixel;
  398.     unsigned char   pixelDepth;
  399.     char            mode = true32b;
  400.     Boolean         swapMode;
  401.         swapMode = PixMap32Bit( thePixMap );
  402.  
  403.     LockPixels( thePixMap );
  404.  
  405.     rowBytes = (unsigned long) ((*thePixMap)->rowBytes & 0x1fff);
  406.     thePixel = (unsigned char *) GetPixBaseAddr( thePixMap );
  407.  
  408.     pixelDepth = (*thePixMap)->pixelSize;
  409.  
  410.     switch ( pixelDepth ) {
  411.             case 1:
  412.         case 2:
  413.         case 4:
  414.         case 8:
  415.  
  416.             thePixel += (rowBytes * y) +
  417.                         (((unsigned long) pixelDepth * x) / 8L);
  418.  
  419.             shiftBits = ((8 - pixelDepth) - ((x * pixelDepth) % 8));
  420.  
  421.             mask = (unsigned char) ((1 << pixelDepth) - 1) << shiftBits;
  422.  
  423.             if ( swapMode ) {
  424.                 SwapMMUMode( &mode );
  425.             }
  426.  
  427.             *thePixel &= ~mask;
  428.             *thePixel |= (unsigned char) value << shiftBits;
  429.  
  430.             break;
  431.  
  432.  
  433.         case 16:
  434.  
  435.             thePixel += (rowBytes * y) + (2L * x);
  436.  
  437.             if ( swapMode ) {
  438.                 SwapMMUMode( &mode );
  439.             }
  440.  
  441.             *((unsigned short *)thePixel) = (unsigned short) value;
  442.  
  443.             break;
  444.  
  445.  
  446.         case 32:
  447.  
  448.             thePixel += (rowBytes * y) + (4L * x);
  449.  
  450.             if ( swapMode ) {
  451.                 SwapMMUMode( &mode );
  452.             }
  453.  
  454.             *((unsigned long *)thePixel) = value;
  455.  
  456.             break;
  457.  
  458.  
  459.         default:
  460.             break;
  461.  
  462.     }
  463.  
  464.     if ( swapMode ) {
  465.         SwapMMUMode( &mode );
  466.     }
  467.  
  468.     UnlockPixels( thePixMap );
  469.  
  470. }
  471.  
  472.  
  473.  
  474. ------------------------------------------------------------------------
  475. 6.4.3  How do you draw directly onto the screen without using QuickDraw?
  476. ------------------------------------------------------------------------
  477.  
  478. Get the pixmap for the monitor that you want to draw on, and send it to the
  479. above procedure.  For example, to draw a red dot at position 10,10 on the
  480. main screen (if the main screen is in 32-bit mode):
  481.  
  482.    GDHandle   theDevice;
  483.  
  484.    theDevice = GetMainDevice();
  485.  
  486.    SetPixel( x, y, 0x00FF0000, (*theDevice)->gdPMap );
  487.  
  488. If you are drawing directly to the screen, you should always wrap your
  489. drawing with calls to ShieldCursor and ShowCursor.  Some monitors such
  490. as the Radius Pivot series keep a virtual screen, and they don't update
  491. the real screen unless they have to.  When you write directly to the
  492. screen, you're actually writing to the virtual screen, and your drawing
  493. won't show up on the real screen until the system has some other reason
  494. to update the monitor.  Calling ShieldCursor each time you draw will
  495. force these systems to update the real screen when you expect them to.
  496.  
  497.  
  498.  
  499. -----------------------------------------------------------------------
  500. 6.4.4  What RGB value does the system use for dimmed buttons, menus and
  501.        window titles?
  502. -----------------------------------------------------------------------
  503.  
  504. The gray color does not have a fixed RGB value.  It is a weighted average of
  505. the foreground and background colors.  To obtain the appropriate 'gray' color
  506. for a given foreground and background color, use the Palette Manager routine
  507. GetGray (documented in Inside Macintosh Volume VI).
  508.  
  509. pascal Boolean GetGray( GDHandle device, const RGBColor *backGround,
  510.                         RGBColor *foreGround )
  511.   = {0x303C,0x1219,0xAAA2};
  512.  
  513. If at least one gray or intermediate color is available, GetGray stores the
  514. color in foreGround and returns true.  If no gray is available, or, if you
  515. supplied two colors, no third distinguishable color is available, the
  516. foreGround parameter is unchanged and the function returns false.
  517.  
  518. GetGray is not available in older versions of the system.  Use Gestalt to
  519. determine whether it is available.
  520.  
  521.  
  522.  
  523.  
  524. 6.5  Files
  525. ----------
  526.  
  527.  
  528. ----------------------------------------------
  529. 6.5.1  Why is the File Manager so hard to use?
  530. ----------------------------------------------
  531.  
  532. Its always those pesky wdrn's that are the problem.  Here is a summary of
  533. some of the things to know:
  534.  
  535.     vrn = volume reference number
  536.           (small negative number; e.g. -2)
  537.     wdrn = working directory reference number
  538.            (large negative number; e.g. -32123)
  539.     dirID = directory ID
  540.             (small (but long integer!) positive number; e.g. 4123)
  541.  
  542.     - vrn's and wdrn's can be used interchangably for the most part.
  543.     - A vrn represents either a volume, or the root directory of a volume.
  544.     - A wdrn represents a directory on a volume.
  545.     - A dirID represents nothing without a vrn or a wdrn.
  546.     - A dirID overrides the directory otherwise specified by the vrn or wdrn
  547.       unless it's zero, in which case it's ignored.  If it is 2 it specifies
  548.       the root directory of the volume.
  549.     - You should always use vrn,dirID pairs. To convert a wdrn into a
  550.       vrn,dirID pair use GetWDInfo, which returns the vRefNum, the dirID and
  551.       the procID of the wdRefNum.  The procID is almost always 'ERIK'.
  552.     - You can also use GetVol/SetVol to convert volume names to/from vrns.
  553.     - To store a vrn,dirID pair (between invocations of a program) convert
  554.       the vrn to a volume name & creation date (for verification) and store
  555.       them and the dirID (and a filename perhaps).
  556.  
  557.  
  558.  
  559. --------------------------------------
  560. 6.5.2  How do you get a full pathname?
  561. --------------------------------------
  562.  
  563. Take a look at Tech Note #238, available from APDA (and other places).  It
  564. tells you everything you need to know to get a full pathname, and why you
  565. should, in general, use a volume name, dirID, filename (and perhaps volume
  566. creation date) triple instead.  Also check out the code snippets available
  567. from ftp.apple.com et al.  There are a couple of snippets that give code to
  568. get a full pathname, as well as many other cool file manager tricks.
  569.  
  570.  
  571.  
  572. --------------------------------------------------
  573. 6.5.3  How do you set the SFGet/PutFile directory?
  574. --------------------------------------------------
  575.  
  576. To set the directory that is displayed by SFGet/PutFile, stuff the volume
  577. reference number into SFSaveDisk, and the dirID into CurDirStore.
  578.  
  579.      CurDirStore = $398;   Current dirID from Standard File (long)
  580.      SFSaveDisk = $214;    Negative of current vRefNum
  581.  
  582.  
  583.  
  584. -----------------------------------------------------
  585. 6.5.3  How do you access the application's data fork?
  586. -----------------------------------------------------
  587.  
  588. Call CurResFile when the application starts up.
  589. Call PBGetFCBInfo to convert that refNum into a vRefNum, dirID and name.
  590. Call HOpen with the vRefNum, dirID, and name to open up your data fork.
  591.  
  592.  
  593.  
  594.  
  595. 6.6  Handles and Pointers
  596. -------------------------
  597.  
  598.  
  599. ----------------------------------
  600. 6.6.1  When should I call MoveHHi?
  601. ----------------------------------
  602.  
  603. MoveHHi is an expensive operation; calling it when you don't need to can
  604. significantly slow down your program.  Additionally, over-calling of MoveHHi
  605. can fragment the top of your heap.  Call MoveHHi before locking a handle that
  606. is followed by some memory allocation.  To efficiently move a handle high in
  607. the heap and then lock it, you might want to call HLockHi, a call new with
  608. MPW 3.2 and THINK C 5.0 (probably THINK Pascal 4.0 as well).
  609.  
  610.  
  611.  
  612. -------------------------------------------------------------------------
  613. 6.6.2  Why does malloc/calloc keep crashing or returning NULL in Think C?
  614. -------------------------------------------------------------------------
  615.  
  616. #include <stdlib.h>
  617.  
  618. Explanation:  In THINK C, parameters and return values are 2-byte ints by
  619. default, which causes the value passed to malloc to be $10000 times as large
  620. as you think it is, and causes the upper bytes of the return value to be
  621. zeroed.  Including stdlib includes a prototype which overrides the defaults.
  622.  
  623. Another common cause of problems with malloc is overwriting the end of a
  624. string, such as only mallocing the size of the string and then writing the
  625. string plus a null into the malloc'd space.  Think's malloc algorithm stores
  626. block size information in space adjacent to the storage it allocates, so
  627. overwriting the storage tends to cause havoc. The problem may not show
  628. immediately since it will probably be the next malloc that encounters
  629. problems.
  630.  
  631.  
  632.  
  633.  
  634. 6.7  Standalone Code
  635. --------------------
  636.  
  637.  
  638. ------------------------------
  639. 6.7.1  How do I write an INIT?
  640. ------------------------------
  641.  
  642. There is a simple INIT (SetWindow INIT) with source code and explanations in
  643. the Usenet Macintosh Programmer's Guide.  There is also a chapter on writing
  644. system extensions in Macintosh Programming Secrets (2nd Ed.).  Be sure to
  645. check out the ftp sites (especially ftp.apple.com) for sample inits.
  646.  
  647.  
  648.  
  649.  
  650. 6.8  General
  651. ------------
  652.  
  653.  
  654. --------------------------------------------------------------
  655. 6.8.1  How do I register signatures and file types with Apple?
  656. --------------------------------------------------------------
  657.  
  658. Registering a signature and file type is free, and you don't have to be an
  659. Apple Partner or Associate.  You can ftp the registration form from
  660. ftp.apple.com; it's available as
  661.      /dts/mac/registration/creator-file-type-form.txt.
  662.  
  663.  
  664.  
  665. -------------------------------------------------------------------------
  666. 6.8.2  How do I go about writing serial port communications?
  667.  
  668. These days, it is best to use the new Comunications Toolbox (CTB).  By
  669. utiizing the CTB, you will be able to write your code to a single
  670. specification, and the code will work with all current CTB "tools" and all
  671. future CTB tools. The CTB tools allow programmers to extend the CTB's
  672. functionality. There is a tool for each facet of the communications puzzle:
  673. Connection Tools, Terminal Tools, and File Transfer Tools.
  674.  
  675. For example, once I have written a piece of code that uses the Serial tool to
  676. connect me to a terminal server, combined with the VT102 Tool to emulate a
  677. vt102 terminal, and the XMODEM Macbinary Tool to transfer files, the same
  678. code will work with Apple Modem Tool, TCP/IP, AppleTalk ADSP, ISDN, X.25, and
  679. all future Connection Tools. Further, the terminal can emulate a VT320,
  680. ASCII, or other terminals. Files may be transfered with XMODEM, TEXT, and
  681. soon ZMODEM and Kermit protocols.
  682.  
  683. The disadvantage of the CTB is that you must limit yourself to the
  684. specification of the Connection, Terminal, and File Transfer interfaces.
  685. These limitations are *rarely* a problem, but clearly something like a FAX
  686. interface program or real time data analyzer, would have to seriously
  687. consider the interfaces before committing.
  688.  
  689. For most standard communications applications, such as terminal emulators,
  690. Bulletin Board Systems, etc., the CTB is the correct choice.
  691.  
  692. You can only get the CTB development kit from APDA.  It is affordable,
  693. somewhere just under $100.  This includes working sample code.
  694.  
  695.  
  696.  
  697.  
  698.  
  699.                       ================================
  700.                         Section VII: Eternal Debates
  701.                       ================================
  702.  
  703.  
  704. These questions have no final answers.  They pop up every few months and
  705. waste a tremendous amount of valuable network resources on discussions
  706. that will never be resolved.  Most people would be happy if they were
  707. never discussed again in this newsgroup.
  708.  
  709.  
  710. 7.1  Why doesn't the Mac do preemptive multitasking?
  711. ----------------------------------------------------
  712.  
  713. Pro-preemptives claim the current scheme is too vulnerable to ill-behaved
  714. applications and too much trouble for application writers.  Anti-
  715. preemptives claim that preemptive multitasking would reduce interactive
  716. response, and that the current cooperative system works well.
  717.  
  718.  
  719.  
  720.  
  721.  
  722.                        ==============================
  723.                          Credits / Acknowledgements
  724.                        ==============================
  725.  
  726.  
  727. Many thanks to Ben Haller, who started this whole thing, and did quite a lot
  728. of work on this posting before handing it off to Michael A. Kelly.  Many
  729. thanks to Michael A. Kelly also, for all his work in establishing and
  730. maintaining this FAQ (in addition to continuing to keep the
  731. Comp.Sys.Mac.Programmer Digest) before passing the baton.
  732.  
  733. Thanks to these people for proofreading this list during its development:
  734.     Ben Haller
  735.     Wally Wedel
  736.     John B. Matthews
  737.     Patrick Beard
  738.     Steve Zellers
  739.  
  740. Thanks to Chris Webster for the one-liners.
  741.  
  742. Thanks to Peter Lewis for the answers to the following specific questions:
  743.     6.2.1  When do you put an ellipsis on the end of a menu item?
  744.     6.5.1  Why is the File Manager so hard to use?
  745.     6.5.2  How do you get a full pathname?
  746.     6.5.3  How do you set the SFGet/PutFile directory?
  747.  
  748. Thanks to Greg Ferrar for the review on TMON Pro.
  749.  
  750. Thanks to John Rinaldo for the review on Jasik's Debugger.
  751.  
  752. Thanks for Fritz Anderson for his descriptions of SourceBug and the new
  753. Inside Macintosh volumes.
  754.  
  755. And thanks to everyone who has offered suggestions or constructive
  756. criticism....  Keep those comments coming!
  757.  
  758.  
  759.  
  760.  
  761. --
  762. -------------------------------------------------------------------
  763.  Daryl_Spitzer@mindlink.bc.ca     "Life isn't just, life just is."
  764.          a2251@mindlink.bc.ca              -- Me  (I think.)
  765. -------------------------------------------------------------------
  766.